package com.gitee.cashzhang27.test.cloud.oauth.auth.server.jdbc.entity;

import java.util.Collection;
import lombok.Builder;
import lombok.Data;
import org.springframework.security.core.CredentialsContainer;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;

/**
 * @author Cash Zhang
 * @version v1.0
 * @since 2019/02/08 20:51
 */
@Data
@Builder
public class UserDetails implements org.springframework.security.core.userdetails.UserDetails,
    CredentialsContainer {

  private String id;
  private String username;
  private String password;
  private String roleId;

  @Override
  public void eraseCredentials() {
    password = null;
  }

  @Override
  public Collection<? extends GrantedAuthority> getAuthorities() {
    String[] dbAuthArr = new String[]{roleId};
    return AuthorityUtils.createAuthorityList(dbAuthArr);
  }


  @Override
  public String getPassword() {
    return password;
  }

  @Override
  public String getUsername() {
    return username;
  }

  @Override
  public boolean isAccountNonLocked() {
    System.out.println(1);
    // true 为未锁定 false 为锁定
    return true;
  }

  @Override
  public boolean isEnabled() {
    // true 未失效 false 为失效
    System.out.println(2);
    return true;
  }

  @Override
  public boolean isAccountNonExpired() {
    // true 未过期 false 已过期
    System.out.println(3);
    return true;
  }

  @Override
  public boolean isCredentialsNonExpired() {
    // true 密码未过期 false 密码已过期
    System.out.println(4);
    return true;
  }
}

